<template>
	<view>
		<view class="namebox">
			<view class="nametit">请输入您的真实姓名，不允许使用特殊字符</view>
			<input class="inname" type="text" placeholder="请输入姓名" v-model="name" />
			<view class="naemte">请如实填写您的真实姓名，便于我们为您提供更方便优质的服务</view>
		</view>
		<view class="namebu" @click="changenaem">完成</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import request from '../../utils/request';
import {onLoad} from '@dcloudio/uni-app'
let name=ref('')
let token=ref()
let text = ref('')
let params = ref('')
onLoad((options)=>{
	token.value=uni.getStorageSync('token')
	text.value = options.text
})
const changenaem=()=>{
	if(name.value==''){
		uni.showToast({
			title:'请输入需要修改的内容',
			icon:'none'
		}) 
	}else{
		if (text.value == 'real') {
			request.post('user/profile',{header:{
					"token":token.value
				}, data:{
					realname: name.value
				}}).then(res=>{
				console.log(res);
			}).catch(err=>{
				console.log(err);
			})
			uni.showToast({
				title:'修改成功',
				
			})
			setTimeout(() => {
			      uni.switchTab({
			      	url: '/pages/myde/myde'
			      })
			    }, 2000);
		} else {
		uni.setStorageSync("name",name.value)
			request.post('user/profile',{header:{
					"token":token.value
				}, data:{
					nickname: name.value
				}}).then(res=>{
				console.log(res);
			}).catch(err=>{
				console.log(err);
			})
			uni.showToast({
				title:'修改成功',
				
			})
			setTimeout(() => {
			      uni.switchTab({
			      	url: '/pages/myde/myde'
			      })
			    }, 2000);
		}
		

		
	}
}
</script>

<style scoped>
	.namebox{
		width: 100%;
		height: 100vh;
		padding:0 30rpx;
		box-sizing: border-box;
		padding-top: 20rpx;
	}
	.nametit{
		font-size: 12px;
		color: #7c7c7c;
	}
	.naemte{
		margin-top: 30rpx;
		font-size: 12px;
		color: red;
	}
	.inname{
		font-size: 13px;
	}
	.namebu{
		width: 690rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		border-radius: 40rpx;
		background-color: #10c696;
		position: fixed;
		bottom: 30rpx;
		left: 30rpx;
		color: #fff;
	}
</style>
